package com.metaera.app.ui.popup;

import android.content.Context;
import android.content.res.Resources;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.lxj.xpopup.core.CenterPopupView;
import com.lxj.xpopup.util.XPopupUtils;
import com.metaera.app.R;
import com.metaera.app.data.model.ProfileResponse;
import com.metaera.app.utils.DateUtils;
import com.metaera.app.utils.image.GlideApp;

import androidx.annotation.NonNull;

public class UserPlatformPopup extends CenterPopupView {

    private ProfileResponse mResponse;

    public UserPlatformPopup(@NonNull Context context) {
        super(context);
    }

    public UserPlatformPopup(@NonNull Context context, ProfileResponse response) {
        super(context);
        mResponse = response;
    }

    @Override
    protected int getImplLayoutId() {
        return R.layout.popup_user_platform;
    }


    @Override
    protected void onCreate() {
        super.onCreate();

        ImageView ivAvatar = findViewById(R.id.iv_avatar);
        TextView tvNickname = findViewById(R.id.tv_nickname);
        TextView tvFollowNumber = findViewById(R.id.tv_follow_number);
        TextView tvFansNumber = findViewById(R.id.tv_fans_number);
        TextView tvArticleNumber = findViewById(R.id.tv_article_number);

        View layout_official_accounts = findViewById(R.id.layout_official_accounts);
        View layout_wechat = findViewById(R.id.layout_wechat);
        View layout_twitter = findViewById(R.id.layout_twitter);
        View layout_weibo = findViewById(R.id.layout_weibo);
        View layout_knowledge_star = findViewById(R.id.layout_knowledge_star);
        View layout_phone_number = findViewById(R.id.layout_phone_number);
        View layout_email = findViewById(R.id.layout_email);

        TextView tv_official_accounts = findViewById(R.id.tv_official_accounts);
        TextView tv_wechat = findViewById(R.id.tv_wechat);
        TextView tv_twitter = findViewById(R.id.tv_twitter);
        TextView tv_weibo = findViewById(R.id.tv_weibo);
        TextView tv_knowledge_star = findViewById(R.id.tv_knowledge_star);
        TextView tv_phone_number = findViewById(R.id.tv_phone_number);
        TextView tv_email = findViewById(R.id.tv_email);

        if (!TextUtils.isEmpty(mResponse.getOfficial_account())){
            layout_official_accounts.setVisibility(View.VISIBLE);
            tv_official_accounts.setText(mResponse.getOfficial_account());
        }

        if (!TextUtils.isEmpty(mResponse.getWechat()) && mResponse.getIs_show_wechat() == 1){
            layout_wechat.setVisibility(View.VISIBLE);
            tv_wechat.setText(mResponse.getWechat());
        }

        if (!TextUtils.isEmpty(mResponse.getTwitter())){
            layout_twitter.setVisibility(View.VISIBLE);
            tv_twitter.setText(mResponse.getTwitter());
        }

        if (!TextUtils.isEmpty(mResponse.getWeibo())){
            layout_weibo.setVisibility(View.VISIBLE);
            tv_weibo.setText(mResponse.getWeibo());
        }

        if (!TextUtils.isEmpty(mResponse.getKnowledge_planet())){
            layout_knowledge_star.setVisibility(View.VISIBLE);
            tv_knowledge_star.setText(mResponse.getKnowledge_planet());
        }

        if (!TextUtils.isEmpty(mResponse.getPhone()) && mResponse.getIs_show_phone() == 1){
            layout_phone_number.setVisibility(View.VISIBLE);
            tv_phone_number.setText(mResponse.getPhone());
        }

        if (!TextUtils.isEmpty(mResponse.getEmail())){
            layout_email.setVisibility(View.VISIBLE);
            tv_email.setText(mResponse.getEmail());
        }

        tvNickname.setText(mResponse.getNickname());
        tvFansNumber.setText(String.valueOf(mResponse.getFans_num()));
        tvFollowNumber.setText(String.valueOf(mResponse.getFollow_num()));
        tvArticleNumber.setText(String.valueOf(mResponse.getActivity_num()));

        GlideApp.with(ivAvatar).load(mResponse.getAvatar_img()).avatar().into(ivAvatar);
    }

}
